package com.cqupt.controller;

import com.cqupt.pojo.ResponseMessage;
import com.cqupt.service.SolrService;
import org.apache.poi.hssf.record.formula.functions.T;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@CrossOrigin
@Controller
@RequestMapping("solrSearch")
@ResponseBody
public class SolrController {
    @Autowired
    private SolrService solrService;

    /**
     * 获取 solr 查询的结果
     * @param params 要检索的字段
     * @return 查询 solr 的结果
     * @throws IOException
     * @throws SolrServerException
     */
    @RequestMapping("/get_solr_result_by_nlr")
    public ResponseMessage getSolrResultByNLR(@RequestBody Map<String, Object> params) throws IOException, SolrServerException {
        ResponseMessage message = new ResponseMessage();
        System.out.println(params);
        Map<String, Object> result = solrService.getQueryResultByNLR(params);
        message.setStatus(true);
        message.setContent(result);
        return message;
    }
}
